<template>
<h1>表格组件</h1>
  <el-table :data="tableData">
<!--  prop=property属性 设置当前列显示的内容来自于数组中对象的哪个属性
label是当前列的表头内容 width设置列宽-->
    <el-table-column prop="date" label="Date" />
    <el-table-column prop="name" label="Name" />
    <el-table-column prop="address" label="Address" />
  </el-table>
  <h3>员工列表</h3>
  <el-table :data="arr" stripe border >
    <el-table-column type="index" label="编号" width="100px"></el-table-column>
    <el-table-column prop="name" label="姓名"></el-table-column>
    <el-table-column prop="salary" label="工资"></el-table-column>
    <el-table-column prop="job" label="工作"></el-table-column>
    <el-table-column label="Operations">
<!--scope里面装着当前行的数据包括:
$index代表当前行的下标, row代表当前行对应的数组里面的对象-->
      <template #default="scope">
        <el-button size="small" type="danger"
            @click="handleDelete(scope.$index, scope.row)"
        >Delete</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const handleDelete = (i,emp)=>{
  if (confirm("您确定删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}
const arr = ref([{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"},
  {name:"王五",salary:5000,job:"出纳"},{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"},
  {name:"王五",salary:5000,job:"出纳"}]);

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>

<style scoped>

</style>